import type { CartItem, CartParams } from '@/types/cart'
import http from '@/utils/http'

/**
 * 加入会员购物车
 * @param data 购物车SKU参数
 */
export const postMemberCartAPI = (data: CartParams) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data
  })
}

/**
 * 获取会员购物车列表
 */
export const getMemberCartAPI = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

/**
 * 删除会员购物车
 * @param ids SKUID数组
 */
export const deleteMemberCartAPI = (ids: string[]) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data: {
      ids
    }
  })
}

/**
 * 修改购物车单品
 * @param skuId SKUID
 * @param data Body参数
 */
export const putMemberCartAPI = (skuId: string, data: {
  selected?: boolean
  count?: number
}) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data
  })
}

/**
 * 商品全选/取消全选
 * @param selected 全选的选中状态
 */
export const putMemberCartSelectedAPI = (selected: boolean) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data: {
      selected
    }
  })
}
